package com.jackrain.nea.fc.cp.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSONObject;
import com.jackrain.nea.exception.NDSException;
import com.jackrain.nea.fc.cp.api.LdapConnectionCmd;
import com.jackrain.nea.util.ValueHolder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;

/**
 * Created by ZCY on 2018/1/8.
 *  * LDAP连接测试
 */
@Slf4j
@Api(value = "LDAP连接", description = "LDAP连接测试")
@RestController
public class ldapctrl {
    @Reference(version = "1.0", group = "cp")
    private LdapConnectionCmd ldapConnectionCmd;

    @ApiOperation(value = "ladp的连接测试")
    @RequestMapping(path = "/p/c/ldapconnectiontest", method = RequestMethod.GET)
    public JSONObject cpchruserssaves(HttpServletRequest request) throws Exception {

        ValueHolder result = new ValueHolder();
        try {
            HashMap map = new HashMap(16);
            result = (ValueHolder) ldapConnectionCmd.execute(map);
        } catch (Exception e) {
            throw new NDSException(e.getMessage(), e);
        }

        return result.toJSONObject();

    }


}
